package com.smart.controller;


import com.smart.common.ResultVo;
import com.qiniu.http.Response;
import com.smart.common.ResultVo;
import com.smart.service.UploadPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @description:
 * @author: LUCKY
 * @time: 2023/2/10 15:54
 */

@RestController
@RequestMapping("/api/upload")
public class UploadController {
    @Autowired
    private UploadPictureService uploadPictureService;

    @PostMapping("/picture")
    @CrossOrigin
    public ResultVo uploadPicture(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        String pictureUrl = uploadPictureService.uploadPicture(multipartFile,"");
        System.out.println(pictureUrl);
        return ResultVo.ok().data("item", pictureUrl);
    }

    @PostMapping("/picture/feedback")
    @CrossOrigin
    public ResultVo uploadPictureFeedback(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        String pictureUrl = uploadPictureService.uploadPicture(multipartFile,"Feedback/");
        System.out.println(pictureUrl);
        return ResultVo.ok().data("item", pictureUrl);
    }

    @PostMapping("/picture/work")
    @CrossOrigin
    public ResultVo uploadPictureWork(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        String pictureUrl = uploadPictureService.uploadPicture(multipartFile,"Work/");
        System.out.println(pictureUrl);
        return ResultVo.ok().data("item", pictureUrl);
    }
}
